import getApiData from "@/services/cpasRequest";






// 获取账表单据列表
// account.ZBAdujst.getBillList
export async function getBillList(whereFrom: string, params: {
  dbname: string,
  Data_ID: string,
  TZQJ: number,
  isTZ: string,
  isShowJZ: boolean,
  isShowDetail: boolean,
  // pageNum: number,
  // pageSize: number,
  // TZLX?: any
} & any) {

  let requestName: any = '';
  if (whereFrom === '账表调整') {
    requestName = 'account.ZBAdjust.Bill.getDataList';
  } else {
    requestName = 'account.auditAdjust.Bill.getDataList';
  }
  // if (params.TZLX === 0) {
  //   delete params.TZLX
  // }


  // params = { ...params, minRN: (params.pageNum - 1) * params.pageSize }


  const res = await getApiData(requestName, params);
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      // total: res.data.total,
      success: true,
    });
  }
  return Promise.resolve({
    data: [],
    // total: 0,
    success: false,
  });
}



// 获取某单据的表单信息 只需传 tmp-billID
export async function getReportItemsData(whereFrom: string, params: {
  dbname: string;
  billID: string
}) {

  let requestName: any = '';
  if (whereFrom === '账表调整') {
    requestName = 'account.ZBAdjust.getOneBill';
  } else {
    requestName = 'account.auditAdjust.getOneBill';
  }
  const res = await getApiData(requestName, params);
  if (res.ok) {
    return res.data;
  }
  return [];
}

// 获取某单据的分录明细 只需传 tmp-billID
export async function getOneBillDetail(whereFrom: string, params: {
  dbname: string;
  billID: string;
  isRefresh?: boolean;
} & any) {

  let requestName: any = '';
  if (whereFrom === '账表调整') {
    requestName = 'account.ZBAdujst.getOneBillDetail';
  } else {
    requestName = 'account.auditAdjust.getOneBillDetail';
  }
  const res = await getApiData(requestName, params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
  // return res
}

// 获取某单据的结转分录明细 只需传 tmp-billID
export async function getOneBillDetailOfJZ(whereFrom: string, params: {
  dbname: string;
  billID: any;
}) {
  let requestName: any = '';
  if (whereFrom === '账表调整') {
    requestName = 'account.ZBAdujst.getOneBillDetailOfJZ';
  } else {
    requestName = 'account.auditAdjust.getOneBillDetailOfJZ';
  }
  const res = await getApiData(requestName, params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}
// 删除单据
export async function ZBAdjustDel(whereFrom: string, params: {
  dbname: string;
  billIDs: any;
  editUser: string | undefined;
  Data_ID: string
}) {
  let requestName: any = '';
  if (whereFrom === '账表调整') {
    requestName = 'account.ZBAdjust.bill.del';
  } else {
    requestName = 'account.auditAdjust.bill.del';
  }

  const res = await getApiData(requestName, params);
  if (res.ok) {
    return res.data;
  }
  return {};
}

// 滚调单据
export async function rollBills(whereFrom: any, params: {
  dbname: string;
  billIDs: any;
  trueName: string | undefined;
  userCode: string
}) {

  let requestName: any = '';
  if (whereFrom === 1 || whereFrom === '账表调整') {
    requestName = 'account.ZBAdjust.rollBill';
  } else {
    requestName = 'account.auditAdjust.rollBill';
  }

  const res = await getApiData(requestName, params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

export async function AddZBAdjust(whereFrom: string, params: {
  dbname: string,
  billID: string,
  GUID: string,
  Data_ID: string,
  KMBH: string,
  KMMC: string,
  PKMBH: string,
  YSKMBH: string,
  YSKMMC: string,
  itemNames3: string,
  YSHSXMBH: string,
  YSHSXMMC: string,
  HSXMBH: string,
  HSXMMC: string,
  HSXMLXBH: string,
  HSXMLXMC: string,
  JF: string,
  DF: string,
  isHCFSE: string,
  XH: string | number,
  remark: string
}) {
  let requestName: any = '';
  if (whereFrom === '账表调整') {
    requestName = 'account.ZBAdjust.detail.edit';
  } else {
    requestName = 'account.auditAdjust.detail.edit';
  }
  const res = await getApiData(requestName, params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}




// 获取已滚调单据列表
export async function getRollBillListed(params: {
  dbname: string;
  billIDs: string;
}) {
  try {
    const res = await getApiData("account.adjustingEntry.getRollBillList", params);
    return Promise.resolve({
      data: res.data,
      success: res.ok,
    });
  } catch (error) {
    return Promise.resolve({
      data: '获取已滚调单据列表,请求失败！',
      success: false,
    });
  }
}


// 重算单据
export async function everyreCaljustBill(params: {
  Data_ID: string,
  dbname: string,
  editUser: string,
  isRecalTZ: boolean;
}) {
  const res = await getApiData('account.reportItem.reCal', params);
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.resolve({
    data: res.data,
    success: false,
  });
};